<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button type="button" onclick="DayOfYear(1997,12,27)" value="点击">点击</button>
    <script>
 /*
3.设计一个函数DayOfYear(d)，它接必一个日期参数d，返回一个该日期是所在年份的第几天，如DayOfYear(2000,2,8)的返回值是39.
提示：
①定义一个数组var months= [31,28,31,30,31,30,31,31,30,31,30,31]记录每个月多少天
②定义一个辅助函数IsLeapYear(year)判定某个年份是否闰年，以确定2月份的天数是28还是29。*/
        function IsLeapYear(year) {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
                return true;
            }
            return false;
        }
        function DayOfYear(year,month,day) {
            var months = [31,28,31,30,31,30,31,31,30,31,30,31];
            var isLeap = IsLeapYear(year);
            if (isLeap){
                months.splice(1,1,29);
            }
            var sumDay = 0;
            for (let i = 0; i < (month - 1); i++) {
                sumDay += months[i];
            }
            sumDay += day;
            alert(sumDay);
        }

    </script>
</body>
</html>